/**
 * @param {string[]} words
 * @return {number}
*/
var uniqueMorseRepresentations = function(words) {
  if(words.length <= 1) return words.length;
  let map = new Map(), strArr = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."], result = new Array(words.length).fill(""), set = new Set();
  for(let i = 0; i < strArr.length; i++) {
    map.set('a'.charCodeAt() + i, strArr[i]);
  }
  for(let i = 0; i < words.length; i++) {
    for(let j = 0; j < words[i].length; j++) {
      result[i] += map.get(words[i][j].charCodeAt());
    }
    set.add(result[i]);
  }
  return set.size;
};
let words = ["gin", "zen", "gig", "msg"];
console.log(uniqueMorseRepresentations(words));
words = ["a"];
console.log(uniqueMorseRepresentations(words));
